package model.dao;

import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import model.Equipamento;
import model.Setor;
import model.Usuario;

public class Popular {
	



	public void popularMysql() throws SQLException, ClassNotFoundException{
		
		PreparedStatement stm;
		String sql="";
	
		
		String url = "jdbc:mysql://localhost:3306/Controle_de_chamados";   
		Class.forName("com.mysql.jdbc.Driver");   
		java.sql.Connection con;   
		con = DriverManager.getConnection(url,"root","123456");  
		
		sql="delete from chamado";
		stm = con.prepareStatement(sql);
		stm.executeUpdate();
		
		sql="delete from usuario";
		stm = con.prepareStatement(sql);
		stm.executeUpdate();
		
		sql="delete from equipamento";
		stm = con.prepareStatement(sql);
		stm.executeUpdate();
		
		sql="delete from setor";
		stm = con.prepareStatement(sql);
		stm.executeUpdate();
		
		sql="insert into setor values (1,'Diretoria','João',1)";
		stm = con.prepareStatement(sql);
		stm.executeUpdate();
		
		sql="insert into setor values (2,'TI','Zeca',10)";
		stm = con.prepareStatement(sql);
		stm.executeUpdate();
		
		sql="insert into usuario values (1,'ADM','Administrador','admin',' ',1)";
		stm = con.prepareStatement(sql);
		stm.executeUpdate();
		
		sql="insert into usuario values (4,'Zé','Tecnico','ze','ze',2)";
		stm = con.prepareStatement(sql);
		stm.executeUpdate();
		
		sql="insert into usuario values (2,'Pedro','Atendente','123','123',2)";
		stm = con.prepareStatement(sql);
		stm.executeUpdate();
		
		sql="insert into usuario values (3,'Luiza','Gerente','123','123',1)";
		stm = con.prepareStatement(sql);
		stm.executeUpdate();
		
		sql="insert into equipamento (num_serie,marca,tipo,garantia,id_setor) values (2424,'LG','Monitor LCD','S',1)";
		stm = con.prepareStatement(sql);
		stm.executeUpdate();
		
		sql="insert into equipamento (num_serie,marca,tipo,garantia,id_setor) values (2425,'LG','Notebook','S',1)";
		stm = con.prepareStatement(sql);
		stm.executeUpdate();
		
		sql="insert into chamado (num_chamado,id_atendente,id_tecnico,id_solicitante,data_abertura,descrição,status,num_serie_equip)values (1,2,1,3,'2013-5-16 19:15:55','Não liga.','Aberto',2425)";
		stm = con.prepareStatement(sql);
		stm.executeUpdate();
		
		stm.close();
		con.close();
	}
	
	public void popularArray() throws ClassNotFoundException, SQLException{
		
		RepositorioSetorArray rpst =new RepositorioSetorArray();
		rpst.inserirSetor(new Setor(1,"Diretoria","João",1));
		rpst.inserirSetor(new Setor(2,"TI","Zeca",10));
		RepositorioUsuarioArray rpuser = new RepositorioUsuarioArray();
		rpuser.inserirUsuario(new Usuario(1,"ADM","Administrador","admin"," ",1));
		rpuser.inserirUsuario(new Usuario(4,"Zé","Tecnico","ze","ze",10));
		rpuser.inserirUsuario(new Usuario(2,"Pedro","Atendente","123","123",10));
		rpuser.inserirUsuario(new Usuario(3,"Luiza","Gerente","123","123",1));
		RepositorioEquipamentoArray rpequip = new RepositorioEquipamentoArray();
		rpequip.inserirEquipamento(new Equipamento(2424,"LG","Monitor LCD","S",10));
		rpequip.inserirEquipamento(new Equipamento(2425,"LG","Notebook","S",1));
		//RepositorioChamadoArray rpcmd = new RepositorioChamadoArray();
		//rpcmd.inserirChamado(new Chamado(1,2,1,3,2425,"Não liga.","?","Aberto"));
		
	}
	
public void limparBDMysql() throws SQLException, ClassNotFoundException{
		
		PreparedStatement stm;
		String sql="";
	
		
		String url = "jdbc:mysql://localhost:3306/Controle_de_chamados";   
		Class.forName("com.mysql.jdbc.Driver");   
		java.sql.Connection con;   
		con = DriverManager.getConnection(url,"root","123456");  
		
		sql="delete from chamado";
		stm = con.prepareStatement(sql);
		stm.executeUpdate();
		
		sql="delete from usuario";
		stm = con.prepareStatement(sql);
		stm.executeUpdate();
		
		sql="delete from equipamento";
		stm = con.prepareStatement(sql);
		stm.executeUpdate();
		
		sql="delete from setor";
		stm = con.prepareStatement(sql);
		stm.executeUpdate();
		
		sql="insert into usuario values (1,'ADM','Administrador','admin',' ',1)";
		stm = con.prepareStatement(sql);
		stm.executeUpdate();
}
}